package com.smart.campus.web.controller.attendance;

import com.smart.campus.common.annotation.Log;
import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.domain.AjaxResult;
import com.smart.campus.common.core.page.TableDataInfo;
import com.smart.campus.common.enums.BusinessType;
import com.smart.campus.common.utils.poi.ExcelUtil;
import com.smart.campus.school.domain.AttendanceRecord;
import com.smart.campus.school.domain.Student;
import com.smart.campus.school.domain.vo.AttendanceResultVo;
import com.smart.campus.school.service.IAttendanceRecordService;
import com.smart.campus.school.service.IAttendanceResultService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 打卡记录Controller
 * 
 * @author Zhihe.Li
 * @date 2020-10-21
 */
@Controller
@RequestMapping("/school/attendance/result")
public class AttendanceResultController extends BaseController
{
    private String prefix = "school/attendance/result";

    @Autowired
    private IAttendanceRecordService attendanceRecordService;
    @Autowired
    private IAttendanceResultService attendanceResultService;


    @GetMapping()
    public String record()
    {
        return prefix + "/list";
    }

    /**
     * 查询考勤结果列表
     */
    //@RequiresPermissions("school:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list()
    {
        startPage();
        Student student = new Student();
        List<AttendanceResultVo> list = attendanceResultService.selectAttendanceResultList(student);
        return getDataTable(list);
    }

    /**
     * 导出打卡记录列表
     */
    @RequiresPermissions("school:record:export")
    @Log(title = "打卡记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AttendanceRecord attendanceRecord)
    {
        List<AttendanceRecord> list = attendanceRecordService.selectAttendanceRecordList(attendanceRecord);
        ExcelUtil<AttendanceRecord> util = new ExcelUtil<AttendanceRecord>(AttendanceRecord.class);
        return util.exportExcel(list, "record");
    }
}
